﻿using System;

namespace Hxsoft.AppV1._Controls
{
	public partial class MessageBox : Hxsoft.AppV1.UserControl
	{
		#region Res
		protected string PromptText
		{
			get { return Res.MessageBox_PromptText; }
		}

		protected string WarningText
		{
			get { return Res.MessageBox_WarningText; }
		}

		protected string ErrorText
		{
			get { return Res.MessageBox_ErrorText; }
		}

		protected string NavTipText
		{
			get { return Res.MessageBox_NavTipText; }
		}

		protected string NavNextMsgText
		{
			get { return Res.MessageBox_NavNextMsgText; }
		}

		protected string NavForeMsgText
		{
			get { return Res.MessageBox_NavForeMsgText; }
		}

		protected string BackText
		{
			get { return Res.MessageBox_BackText; }
		}

		protected string CloseText
		{
			get { return Res.MessageBox_CloseText; }
		}

		protected string AutoGoTipText
		{
			get { return Res.MessageBox_AutoGoTipText; }
		}
		#endregion

		private LoadedValue<int> loadedWidth;
		public int Width
		{
			get
			{
				if (loadedWidth.Loader == null)
					loadedWidth.Loader = () => IntExtensions.ConvertFromOrDefault(ViewState["Width"], 380);
				return loadedWidth.Value;
			}
			set
			{
				if (loadedWidth.Setter == null)
					loadedWidth.Setter = v => ViewState["Width"] = v;
				loadedWidth.Value = value;
			}
		}

		private LoadedValue<int> loadedHeight;
		public int Height
		{
			get
			{
				if (loadedHeight.Loader == null)
					loadedHeight.Loader = () => IntExtensions.ConvertFromOrDefault(ViewState["Height"], 200);
				return loadedHeight.Value;
			}
			set
			{
				if (loadedHeight.Setter == null)
					loadedHeight.Setter = v => ViewState["Height"] = v;
				loadedHeight.Value = value;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected override void OnPreRender(EventArgs e)
		{
			this.ApplicationPage.RegisterHeadIncludeFile(ApplicationConfiguration.JQueryUrl, IncludeFileType.JS);
			this.ApplicationPage.RegisterHeadIncludeFile(ApplicationConfiguration.JQueryBlockUIUrl, IncludeFileType.JS);
			this.ApplicationPage.RegisterHeadIncludeFile(ApplicationConfiguration.MessageBoxScriptUrl, IncludeFileType.JS);
			this.ApplicationPage.RegisterHeadIncludeFile(ApplicationConfiguration.MessageBoxStyleUrl, IncludeFileType.CSS);

			base.OnPreRender(e);
		}

		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			base.Render(writer);
			writer.Write(@"<input id=""" + PageMessage.ClientMessageKey + @""" type=""hidden"" value=""" + GetPageMessages() + @""" />");
		}

		protected string GetPageMessages()
		{
			return PageMessage.EncodeMessages(this.ApplicationPage.Messages);
		}
	}
}